package com.algorithms.leetcode.Arrays;

/**
 * 假设你正在爬楼梯。需要 n 阶你才能到达楼顶。
 * 每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢？
 * https://leetcode-cn.com/problems/climbing-stairs/
 * <br>
 */
public class leetcode_70_climbStairs {


    public int climbStairsV1(int n) {
        int[] dp = new int[n+1];
        dp[0] = 1;
        dp[1] = 1;
        for(int i = 2;i < n + 1;i++){
            dp[i] = dp[i-1] + dp[i-2];
        }
        return dp[n];
    }


    public int climbStairsV2(int n) {
        int prev = 1;
        int current = 1;
        for(int i = 2;i < n + 1;i++){
            int tmp = current;
            current = prev + current;
            prev = tmp;
        }
        return current;
    }



}
